4. CIA & Encoding

The CIA Triad

confidentiality, integrity, availability is important for information security. These 3 components should be present in a secure system.

Encoding

Encoding is not really cryptography, it is a technique of converting data from one form to another.
It is reversible.

Types Of Encoding

  1. Character encoding
    In it characters are encoded as bytes. Since computers only recognize binary data, text must be represented in a binary form. This is accomplished by converting each character (which includes letters, numbers, symbols, and spaces) into a binary code.
    Common types of text encoding include ASCII and Unicode.

Demo:
To find out encoding present in a webpage:

Right click> View/Page source> Open HTML of the page

A page that uses UTF-8 encoding may include one of the following text:

In HTML 5: <meta charset="UTF-8">

539d67b76fd94568c8a9db9124bcc8b6.png

OR

Right click>Page Info

bbc058504ede23750a31a2be58de8908.png


  1. Base Encoding

In it binary data is converted to ASCII.
It is used when binary data, such as images or video, needs to be transmitted in a plain-text (ASCII) format.

1f1cd40d600329fbd79dd3bb5b030a4d.png

Binary
Binary is 0 or 1 which represents state of electricity in the microchips (1=ON , 0=OFF).

We use base10 (decimal) numerical system.
Means the numbers are made of 10 symbols from 0 to 9.
All base systems works on positional notation.
Means we put a number at the left side.
Like in base10 when we get to a number divisible by 10 we add a digit (1) to the left.
Each new value will be 10 times greater.

4f5940d9cc0ffaed7788efaddb134888.png

All base systems after base10 are AlphaNumeric (uses Alphabets to represent numbers > 9).

Base2 (Binary)

2b1bb8c1e9ac073e2f71d57ab4610374.png

599057388b366a3d3069410e508ec65e.png

155 represented in Base2

9cfb5ec55339df3f3e7f653e6dd6f0dd.png

Sum only those which are ON (have 1).

Base64

2^6 = 64 characters

Binary data is broken into 6-bit segments and then converted to ASCII characters using the table.

c9a24860ee0794320d8fbfa307348457.png

d277a61a05d75311a4a6011163018790.png

In ASCII, A = 65 same for n & d.
We break 'AND' into binary,then those binaries into 6 bits and then the result into ASCII and map ASCII chars with base64 table to obtain the base64 values.

Note: A base64 encoded string doesn't always end with a =, it will only end with one or two = if they are required to pad the string out to the proper length.

2df45b78bb508443f47b2d69806fbbd6.png

Base64 encoding, decoding

b7820fc90a686ff25d4612a498740f91.png

Authorization: Basic bXl1c2VyOm15cGFzc3dvcmQ=

data:[<mediatype>][;base64],<data>

data:URL are used to include in-line data in HTML webpages like a image.

Example:
An image of a small red dot.

Red dot

9a13a65ded695856dd31c4daa1a4d196.png


  1. URL Encoding
    URLs can only be sent over the Internet using the ASCII character-set. If a URL contains characters outside the ASCII set, the URL has to be converted.

  1. HTML Form Encoding
    It is used when sending form data and request parameters to the server.
    The encoding type of a form is determined by the attribute enctype, which has 3 values:

839316e34180fa00e69633bbe6e25d36.png

Above, the form is submitted using POST request.

The action attribute specifies where to send the form-data when a form is submitted.

The & ampersand acts as a delimiter between each (name, value) pair, enabling the server to understand when and where a parameter value starts and ends.

A delimiter is one or more characters that separate text strings.

f87e9e930fcdb431c0d721a262341b5e.png

Chrome represents form fields under Form Data.
And as we can see the spaces in URL are encoded (replaced by either '%20' or '+').

6e091a09e3d757cd8c51821d4be382a6.png

c62782e7d46656d65d99d0dbf94ef025.png

In content-type header the boundary value tells the server to understand when and where a parameter value starts and ends.

Request Payload contains the form fields.

The entire payload is terminated by the boundary value suffixed with a --.

The hyphens themselves are not part of the boundary value but rather needed as part of the request format.


  1. UUEncode
    The Unix-2-Unix encoding is used to encode data for transmission in mediums that only support ASCII data like emails.
    It has now been largely replaced by MIME and yEnc.

  1. XOR encoding
    Used to store passwords in configuration files. Used by IBM WebSphere Application Server.